"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
var app = getApp();
exports.default = Page({
  data: {
    userInfo: {
      avatar: "../../../static/image/avatar.png",
      name: "",
      nickname: "",
      mobile: "",
      wechat: "",
      idcard: "",
      company: ""
    }
  },
  onLoad: function onLoad() {
    var _this = this;
    var openid = wx.getStorageSync("openid");
    var userInfo = wx.getStorageSync("info");
    _this.setData({
      openid: openid,
      userInfo: userInfo
    });
  },
  upload: function upload() {
    var _this = this;
    wx.chooseImage({
      // 设置数量，默认9
      count: 1,
      // 可以指定是原图还是压缩图，默认二者都有
      sizeType: ["original", "compressed"],
      // 可以指定来源是相册还是相机，默认二者都有
      sourceType: ["album", "camera"],
      success: function success(res) {
        var tempFilePaths = res.tempFilePaths;
        wx.uploadFile({
          url: app.globalData.host, //仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          header: {
            "content-type": "multipart/form-data"
          },
          name: "file",
          formData: {
            mod: "do",
            act: "upload"
          },
          success: function success(res) {
            _this.setData({
              avatar: res.data
            });
          }
        });
      }
    });
  },
  upDateInfo: function upDateInfo(e) {
    var _this = this;
    var name = e.detail.value.name;
    var nickname = e.detail.value.nickname;
    var mobile = e.detail.value.mobile;
    var wechat = e.detail.value.wechat;
    var idcard = e.detail.value.idcard;
    var company = e.detail.value.company;
    var tempFilePaths = _this.data.avatar || "";
    wx.request({
      url: app.globalData.host,
      data: {
        mod: "do",
        act: "profile",
        ssid: _this.data.openid,
        name: name,
        nickname: nickname,
        mobile: mobile,
        wechat: wechat,
        idcard: idcard,
        company: company,
        avatar: tempFilePaths
      },
      method: "post", // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function success(res) {
        // success
        //console.log(res);
        wx.showToast({
          title: res.data.txt,
          icon: "none",
          duration: 1000,
          mask: false
        });
      },
      fail: function fail() {
        // fail
      },
      complete: function complete() {
        // complete
      }
    });
  }
});